home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / newart.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-10  |  3.1 KB  |  114 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     newart.c
  4.  
  5.     This module handles checking for new articles.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include <string.h>
  13.  
  14. #include "glob.h"
  15. #include "newart.h"
  16. #include "nntp.h"
  17. #include "mark.h"
  18. #include "util.h"
  19. #include "close.h"
  20.  
  21.  
  22.  
  23. /*----------------------------------------------------------------------------
  24.     DoCheckNewArticles 
  25.     
  26.     Checks to see if there are any new articles on the server for all of the 
  27.     groups in a user group list.
  28.  
  29.     Entry:    wind = pointer to user group list window.
  30. ----------------------------------------------------------------------------*/
  31.  
  32. void DoCheckNewArticles(WindowPtr wind)
  33. {
  34.     TWindow **info;
  35.     ListHandle theList;
  36.     TGroup **groupArray;
  37.     short numGroups, numCells, cellDataLen, groupIndex;
  38.     Cell theCell;
  39.     TGroup theGroup;
  40.     long numUnread;
  41.     Boolean haveSelectedGroup;
  42.     TUnread **cur, **prev;
  43.     
  44.     StatusWindow("Checking for new articles.");
  45.     
  46.     info = (TWindow**)GetWRefCon(wind);
  47.     groupArray = (**info).groupArray;
  48.     numGroups = (**info).numGroups;
  49.     theList = (**info).theList;
  50.     numCells = (**theList).dataBounds.bottom;
  51.     theCell.h = 0;
  52.     
  53.     /* Close all child windows. */
  54.     
  55.     while ((**info).childList != nil) DoCloseWindow((**(**info).childList).childWindow);
  56.     
  57.     /* Add [lastMess+1, maxlong] to the end of each group unread list. 
  58.        Mark each group in the list for an article range update. */
  59.     
  60.     for (theCell.v = 0; theCell.v < numCells; theCell.v++) {
  61.         cellDataLen = 2;
  62.         LGetCell(&groupIndex, &cellDataLen, theCell, theList);
  63.         theGroup = (*groupArray)[groupIndex];
  64.         numUnread = theGroup.numUnread;
  65.         AppendUnreadRange(theGroup.lastMess+1, 0x7fffffff, &theGroup);
  66.         theGroup.numUnread = numUnread;
  67.         theGroup.status = 'x';
  68.         (*groupArray)[groupIndex] = theGroup;
  69.     }
  70.     
  71.     /* Get new group article ranges from server. */
  72.  
  73.     GetGroupArrayArticleRanges(groupArray, numGroups);
  74.     
  75.     /* Adjust unread lists and redraw unread article counts. Select the first
  76.        group with unread articles, if any. */
  77.     
  78.     haveSelectedGroup = false;
  79.     for (theCell.v = 0; theCell.v < numCells; theCell.v++) {
  80.         cellDataLen = 2;
  81.         LGetCell(&groupIndex, &cellDataLen, theCell, theList);
  82.         theGroup = (*groupArray)[groupIndex];
  83.         if (theGroup.status == 'x') {
  84.             AdjustUnreadList(&theGroup);
  85.             theGroup.onlyRedrawCount = true;
  86.             (*groupArray)[groupIndex] = theGroup;
  87.             LDraw(theCell, theList);
  88.             (*groupArray)[groupIndex].onlyRedrawCount = false;
  89.             if (haveSelectedGroup || theGroup.numUnread == 0) {
  90.                 LSetSelect(false, theCell, theList);
  91.             } else {
  92.                 LSetSelect(true, theCell, theList);
  93.                 haveSelectedGroup = true;
  94.             }
  95.         } else {
  96.             theGroup.firstMess = 1;
  97.             theGroup.lastMess = 0;
  98.             theGroup.numUnread = 0;
  99.             cur = theGroup.unread;
  100.             while (cur != nil) {
  101.                 prev = cur;
  102.                 cur = (**cur).next;
  103.                 MyDisposHandle((Handle)prev);
  104.             }
  105.             theGroup.onlyRedrawCount = true;
  106.             (*groupArray)[groupIndex] = theGroup;
  107.             LDraw(theCell, theList);
  108.             (*groupArray)[groupIndex].onlyRedrawCount = false;
  109.         }
  110.     }
  111.     if (haveSelectedGroup) LAutoScroll(theList);
  112. }
  113.  
  114.